package pattern.structure.proxy.statics;

/**
 * @author : Rookie
 * @description : 静态代理模式
 * @date : 2023/10/1
 */
public class StaticProxyPattern {

    public static void main(String[] args) {
        Agent agent = new Agent(850);
        agent.rent();
    }
}

/**
 * 租房业务
 */
interface RentHouse {

    void rent();
}

class Host implements RentHouse {

    private final Integer price;

    public Host(Integer price) {
        this.price = price;
    }

    public Integer getPrice() {
        return this.price;
    }

    @Override
    public void rent() {
        System.out.println("fwc想出租房子,价格是" + price);
    }
}

class Agent implements RentHouse {
    /**
     * 代理价格
     */
    private final Integer agentPrice;
    /**
     * 原有对象
     */
    private Host host;

    public Agent(Integer agentPrice) {
        this.agentPrice = agentPrice;
    }

    @Override
    public void rent() {
        System.out.println("中介公司代理");
        if (host == null) {
            host = new Host(700);
        }
        host.rent();
        System.out.println("中介公司代理完成,赚了" + (agentPrice - host.getPrice()) + "钱");
    }
}
